package com.aifast.system.sys.controller;

import com.aifast.common.annotations.AiIdempotent;
import com.aifast.common.base.Controller;
import com.aifast.common.base.R;
import com.aifast.common.layui.LayuiDataTable;
import com.aifast.system.sys.entity.SysAuthorities;
import com.aifast.system.sys.service.SysAuthoritiesService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 权限 前端控制器
 * </p>
 *
 * @author fujian
 * @since 2022-01-07
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/sys/sysAuthorities")
public class SysAuthoritiesController extends Controller {

    private final SysAuthoritiesService service;

//    @SaCheckPermission("auth:list")
    @GetMapping("list")
    public LayuiDataTable list() {
        return service.list(getSearchValue(), getPage());
    }

//    @AiIdempotent
//    @SaCheckPermission("auth:addOrUpdate")
    @PostMapping("add")
    public R add(SysAuthorities sysAuthorities) {
        return service.insertOrUpdate(sysAuthorities) ? OK() : ERROR();
    }

//    @SaCheckPermission("auth:list")
    @GetMapping("info")
    public R info() {
        return service.info(getInt("id"));
    }

    @AiIdempotent
//    @SaCheckPermission("auth:del")
    @GetMapping("del")
    public R del() {
        return service.del(getInt("id"), get("ids")) ? OK() : ERROR();
    }

    @GetMapping("getAuthTree")
    public R getAuthTree(){
        return service.getAuthTree(getInt("roleId"));
    }

//    @SaCheckPermission("auth:addOrUpdate")
    @PostMapping("addRoleAuth")
    public R addRoleAuth(){
        return service.addRoleAuth(getInt("roleId"),get("authIds")) ? OK() : ERROR();
    }

    @GetMapping("getSideMenu")
    public R getSideMenu(){
        return OK(service.getSideMenu());
    }

}

